package com.gitee.center.test;

import com.gitee.center.CenterServer;
import com.gitee.center.runtime.Center;
import com.gitee.center.runtime.OrderModelCreator;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@SpringBootTest(classes = CenterServer.class)
@RunWith(SpringRunner.class)
public class SubmitOrder {
    @Resource
    private SubmitOrderStepsExec submitOrderStepsExec;

    @Test
    public void submit() {
        OrderModelCreator creator = new OrderModelCreator();
        creator.setSource("KA"); // KVPartner 会触发KV前台相关的扩展点
        creator.setCustomerNo("home");
        creator.setExternalNo("20200987655");
        OrderMain orderModel = OrderMain.createWith(creator);
        List<String> steps = Center.findAbility(DecideStepsAbility.class).decideSteps(orderModel, Steps.SubmitOrder.Activity);

        if (steps != null && !steps.isEmpty()) {
            // 通过步骤编排的模板方法执行每一个步骤，其中涉及到：步骤回滚，步骤重新编排
            submitOrderStepsExec.execute(Steps.SubmitOrder.Activity, steps, orderModel);
        }
    }


}
